<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="css/join.css">
    <script type="text/javascript" src="js/md5.js"></script>
<!--    <link rel="stylesheet"  th:href="@{/static/css/join.css}">-->
<!--    <script type="text/javascript" th:src="@{js/md5.js}"></script>-->
    <script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
    <script>

        L2Dwidget.init({
            "model": {
                "jsonPath": "https://unpkg.com/live2d-widget-model-hijiki@1.0.5/assets/hijiki.model.json",
                "scale": 1
            },
            "display": {
                "position": "left",
                "width": 150,
                "height": 300,
                "hOffset": 0,
                "vOffset": -20
            },
            "mobile": {
                "show": true,
                "scale": 0.5
            },
            "react": {
                "opacityDefault": 0.7,
                "opacityOnHover": 0.2
            }
        });


        function login1(){

        const name=document.getElementById('name');
        const pwd=document.getElementById('password');
            const md5pwd=MD5(pwd.value);
            // alert(md5pwd);
            xhttp.onreadystatechange = function () {
                if (this.readyState === 4 && this.status === 200) {
                    const obj = JSON.parse(this.responseText);
                    if(obj.success){

                    }else {
                        alert(obj.message);
                    }
                    loginin();
                }
            };
            xhttp.open("POST", "/login?name=" + name.value + '&pwd=' + md5pwd , true);
            xhttp.setRequestHeader('Accept', 'application/json');
            xhttp.send();
        }

        function loginin() {
            xhttp.onreadystatechange = function () {
                if (this.readyState === 4 && this.status === 200) {
                    const obj = JSON.parse(this.responseText);
                    if (obj.success) {
                        alert(obj.message);
                        if(obj.message==="欢迎登录,管理员"){
                            window.location.href='index.html';
                        }else {
                            window.location.href='studen.html';
                        }
                    }
                }
            };
            xhttp.open("POST", "/login1"  , true);
            xhttp.setRequestHeader('Accept', 'application/json');
            xhttp.send();
        }

        var xhttp=new XMLHttpRequest();
    </script>
</head>
<body>
<box action="" class="login">
    <p> 登录 客户中心</p>
    <div>
        <input type="text" id="name" class="user-img" placeholder="用户名">
        <span id="thisname"></span>
    </div>
    <div>
        <input type="password" id="password" class="pwd-img" placeholder="密码">
        <span id="thispwd"></span>
    </div>
    <div>
        <input class="inp" type="checkbox" value="">
        <label  class="lable1" >记住俺</label>
    </div>
    <button  type="submit" class="btn" value="登录" onclick="login1()">登录</button>
</box>
</body>
</html>